dict = {"fname":"Joe","lname":"Bloggs","form":"AO","year":10} |
print(dict["fname"] + " " + dict["lname"] + " (" + str(dict["year"]) + dict["form"] + ")") |
1 | dict = {"fname":"Joe","lname":"Bloggs","form":"AO","year":10} |
2 | print(dict["fname"] + " " + dict["lname"] + " (" + str(dict["year"]) + dict["form"] + ")") |
value = input() |
d = {} |
key = input() |
d[key] = value |
1 | d = {} |
2 | key = input() |
3 | value = input() |
4 | d[key] = value |
d = {"english":5,"maths":4,"history":7,"computer science":6,"geography":4,"PE":4} |
print("Enter a subject") |
print(d[s]) |
s = input() |
1 | d = {"english":5,"maths":4,"history":7,"computer science":6,"geography":4,"PE":4} |
2 | print("Enter a subject") |
3 | s = input() |
4 | print(d[s]) |
keys = ["key1","key2","key3","key4","key5"] |
values = ["value1","value2","value3","value4","value5"] |
d[key] = value |
print(d) |
for x in range(5): |
key = keys[x] |
value = values[x] |
d = {} |
keys = ["key1","key2","key3","key4","key5"] |
values = ["value1","value2","value3","value4","value5"] |
    d[key] = value |
print(d) |
for x in range(5): |
    key = keys[x] |
    value = values[x] |
d = {} |
1 | keys = ["key1","key2","key3","key4","key5"] |
2 | values = ["value1","value2","value3","value4","value5"] |
3 | d = {} |
4 | for x in range(5): |
5 |     key = keys[x] |
6 |     value = values[x] |
7 |     d[key] = value |
8 | print(d) |
d[s] = g |
d = {"english":5,"maths":4,"history":7,"computer science":6,"geography":4,"PE":4} |
print("Enter a subject and a grade") |
g = input() |
print(d) |
s = input() |
1 | d = {"english":5,"maths":4,"history":7,"computer science":6,"geography":4,"PE":4} |
2 | print("Enter a subject and a grade") |
3 | s = input() |
4 | g = input() |
5 | d[s] = g |
6 | print(d) |
count[value] = count[value] + 1 |
for x in range(len(values)): |
value = values[x] |
print(count) |
count = {1:0,2:0,3:0,4:0} |
values = [1,2,1,3,2,4,2,1,1,2,3,4] |
    count[value] = count[value] + 1 |
for x in range(len(values)): |
    value = values[x] |
print(count) |
count = {1:0,2:0,3:0,4:0} |
values = [1,2,1,3,2,4,2,1,1,2,3,4] |
1 | values = [1,2,1,3,2,4,2,1,1,2,3,4] |
2 | count = {1:0,2:0,3:0,4:0} |
3 | for x in range(len(values)): |
4 |     value = values[x] |
5 |     count[value] = count[value] + 1 |
6 | print(count) |
allDict = [{"item":4},{"item":2},{"item":7},{"item":2}] |
total = total + allDict[x]["item"] |
print(total) |
total = 0 |
for x in range(len(allDict)): |
allDict = [{"item":4},{"item":2},{"item":7},{"item":2}] |
    total = total + allDict[x]["item"] |
print(total) |
total = 0 |
for x in range(len(allDict)): |
1 | allDict = [{"item":4},{"item":2},{"item":7},{"item":2}] |
2 | total = 0 |
3 | for x in range(len(allDict)): |
4 |     total = total + allDict[x]["item"] |
5 | print(total) |
if item["value"] > 90: |
arr = [] |
for x in range(len(items)): |
items = [{"item":"item4","value":92},{"item":"item2","value":20},{"item":"item1","value":90}] |
item = items[x] |
arr.append(item["item"]) |
    if item["value"] > 90: |
arr = [] |
for x in range(len(items)): |
items = [{"item":"item4","value":92},{"item":"item2","value":20},{"item":"item1","value":90}] |
    item = items[x] |
        arr.append(item["item"]) |
1 | items = [{"item":"item4","value":92},{"item":"item2","value":20},{"item":"item1","value":90}] |
2 | arr = [] |
3 | for x in range(len(items)): |
4 |     item = items[x] |
5 |     if item["value"] > 90: |
6 |         arr.append(item["item"]) |
items = [{"item":"item4","value":92},{"item":"item2","value":20},{"item":"item1","value":90}] |
arr.append(item) |
item = items[x] |
arr = [] |
if item["value"] > 90: |
for x in range(len(items)): |
items = [{"item":"item4","value":92},{"item":"item2","value":20},{"item":"item1","value":90}] |
        arr.append(item) |
    item = items[x] |
arr = [] |
    if item["value"] > 90: |
for x in range(len(items)): |
1 | items = [{"item":"item4","value":92},{"item":"item2","value":20},{"item":"item1","value":90}] |
2 | arr = [] |
3 | for x in range(len(items)): |
4 |     item = items[x] |
5 |     if item["value"] > 90: |
6 |         arr.append(item) |
#Using the dictionary below: |
if value not in count: |
print(count) |
for x in range(len(values)): |
value = values[x] |
values = [1,2,1,3,2,4,2,1,1,2,3,4] |
count = {} |
count[value] = 0 |
count[value] = count[value] + 1 |
#Using the dictionary below: |
    if value not in count: |
print(count) |
for x in range(len(values)): |
    value = values[x] |
values = [1,2,1,3,2,4,2,1,1,2,3,4] |
count = {} |
        count[value] = 0 |
    count[value] = count[value] + 1 |
1 | values = [1,2,1,3,2,4,2,1,1,2,3,4] |
2 | #Using the dictionary below: |
3 | count = {} |
4 | for x in range(len(values)): |
5 |     value = values[x] |
6 |     if value not in count: |
7 |         count[value] = 0 |
8 |     count[value] = count[value] + 1 |
9 | print(count) |
arr = [] |
d["Postcode"] = uk_postcodes[r] |
d = {} |
d["Address"] = str(random.randint(1,100)) + " " + road_names[r] |
arr.append(d) |
d["Age"] = random.randint(18,100) |
print(arr) |
import random |
r = random.randint(0,len(road_names)-1) |
for x in range(10): |
d["Name"] = random.choice(fname) + " " + random.choice(lname) |
arr = [] |
    d["Postcode"] = uk_postcodes[r] |
    d = {} |
    d["Address"] = str(random.randint(1,100)) + " " + road_names[r] |
    arr.append(d) |
    d["Age"] = random.randint(18,100) |
print(arr) |
import random |
    r = random.randint(0,len(road_names)-1) |
for x in range(10): |
    d["Name"] = random.choice(fname) + " " + random.choice(lname) |
1 | import random |
2 | arr = [] |
3 | for x in range(10): |
4 |     d = {} |
5 |     d["Name"] = random.choice(fname) + " " + random.choice(lname) |
6 |     d["Age"] = random.randint(18,100) |
7 |     r = random.randint(0,len(road_names)-1) |
8 |     d["Address"] = str(random.randint(1,100)) + " " + road_names[r] |
9 |     d["Postcode"] = uk_postcodes[r] |
10 |     arr.append(d) |
11 | print(arr) |
value = subDict["fire"] + subDict["water"] + subDict["earth"] + subDict["air"] |
d = {} |
name = subDict["name"] |
print(d) |
for x in range(len(playerArray)): |
d[name] = value |
subDict = playerArray[x] |
    value = subDict["fire"] + subDict["water"] + subDict["earth"] + subDict["air"] |
d = {} |
    name = subDict["name"] |
print(d) |
for x in range(len(playerArray)): |
    d[name] = value |
    subDict = playerArray[x] |
1 | d = {} |
2 | for x in range(len(playerArray)): |
3 |     subDict = playerArray[x] |
4 |     name = subDict["name"] |
5 |     value = subDict["fire"] + subDict["water"] + subDict["earth"] + subDict["air"] |
6 |     d[name] = value |
7 | print(d) |
print(d) |
for key in d: |
d = {"fire":0,"water":0,"earth":0,"air":0} |
for x in range(len(playerArray)): |
subDict = playerArray[x] |
d[key] = d[key] + subDict[key] |
print(d) |
    for key in d: |
d = {"fire":0,"water":0,"earth":0,"air":0} |
for x in range(len(playerArray)): |
    subDict = playerArray[x] |
        d[key] = d[key] + subDict[key] |
1 | d = {"fire":0,"water":0,"earth":0,"air":0} |
2 | for x in range(len(playerArray)): |
3 |     subDict = playerArray[x] |
4 |     for key in d: |
5 |         d[key] = d[key] + subDict[key] |
6 | print(d) |
playerArray[x] = subDict |
subDict["total"] = subDict["fire"] + subDict["water"] + subDict["earth"] + subDict["air"] |
subDict = playerArray[x] |
for x in range(len(playerArray)): |
del subDict["fire"] |
del subDict["earth"] |
del subDict["water"] |
del subDict["air"] |
    playerArray[x] = subDict |
    subDict["total"] = subDict["fire"] + subDict["water"] + subDict["earth"] + subDict["air"] |
    subDict = playerArray[x] |
for x in range(len(playerArray)): |
    del subDict["fire"] |
    del subDict["earth"] |
    del subDict["water"] |
    del subDict["air"] |
1 | for x in range(len(playerArray)): |
2 |     subDict = playerArray[x] |
3 |     subDict["total"] = subDict["fire"] + subDict["water"] + subDict["earth"] + subDict["air"] |
4 |     del subDict["fire"] |
5 |     del subDict["water"] |
6 |     del subDict["earth"] |
7 |     del subDict["air"] |
8 |     playerArray[x] = subDict |
d = {} |
print(d) |
itemName = subDict["item"] |
else: |
d[itemName] = d[itemName] + itemValue |
itemValue = subDict["value"] |
d[itemName] = itemValue |
for x in range(len(itemArray)): |
if itemName not in d: |
subDict = itemArray[x] |
d = {} |
print(d) |
    itemName = subDict["item"] |
    else: |
        d[itemName] = d[itemName] + itemValue |
    itemValue = subDict["value"] |
        d[itemName] = itemValue |
for x in range(len(itemArray)): |
    if itemName not in d: |
    subDict = itemArray[x] |
1 | d = {} |
2 | for x in range(len(itemArray)): |
3 |     subDict = itemArray[x] |
4 |     itemName = subDict["item"] |
5 |     itemValue = subDict["value"] |
6 |     if itemName not in d: |
7 |         d[itemName] = itemValue |
8 |     else: |
9 |         d[itemName] = d[itemName] + itemValue |
10 | print(d) |
for x in range(len(hobbies)): |
letter = letter.upper() |
hobbiesAlpha[letter] = [] |
letter = hobbies[x][0] |
print(hobbiesAlpha) |
if letter not in hobbiesAlpha: |
hobbiesAlpha = {} |
hobbiesAlpha[letter].append(hobbies[x]) |
for x in range(len(hobbies)): |
    letter = letter.upper() |
        hobbiesAlpha[letter] = [] |
    letter = hobbies[x][0] |
print(hobbiesAlpha) |
    if letter not in hobbiesAlpha: |
hobbiesAlpha = {} |
    hobbiesAlpha[letter].append(hobbies[x]) |
1 | hobbiesAlpha = {} |
2 | for x in range(len(hobbies)): |
3 |     letter = hobbies[x][0] |
4 |     letter = letter.upper() |
5 |     if letter not in hobbiesAlpha: |
6 |         hobbiesAlpha[letter] = [] |
7 |     hobbiesAlpha[letter].append(hobbies[x]) |
8 | print(hobbiesAlpha) |
name = playerArray[x]["name"] |
items = [name] |
items.append(name) |
d = {"fire":[],"water":[],"air":[],"earth":[]} |
elif playerArray[x][key] == max: |
for x in range(len(playerArray)): |
max = playerArray[x][key] |
max = -1 |
items = [] |
for key in d: |
if playerArray[x][key] > max: |
d[key] = items |
print(d) |
        name = playerArray[x]["name"] |
            items = [name] |
            items.append(name) |
d = {"fire":[],"water":[],"air":[],"earth":[]} |
        elif playerArray[x][key] == max: |
    for x in range(len(playerArray)): |
            max = playerArray[x][key] |
    max = -1 |
    items = [] |
for key in d: |
        if playerArray[x][key] > max: |
    d[key] = items |
print(d) |
1 | d = {"fire":[],"water":[],"air":[],"earth":[]} |
2 | for key in d: |
3 |     max = -1 |
4 |     items = [] |
5 |     for x in range(len(playerArray)): |
6 |         name = playerArray[x]["name"] |
7 |          |
8 |         if playerArray[x][key] > max: |
9 |             items = [name] |
10 |             max = playerArray[x][key] |
11 |         elif playerArray[x][key] == max: |
12 |             items.append(name) |
13 |     d[key] = items |
14 | print(d) |